package re.jf.echangeur.utilitaire;

import java.io.File;
import java.io.FileFilter;
import java.util.Arrays;
import java.util.List;

class Utils {

  public final static List<String> selection = Arrays.asList("mkv",
    "avi",
    "mov",
    "mp4",
    "mpeg",
    "mpg",
    "wmv",
    "divx",
    "rm",
    "vob",
    "flv");

  /*
   * Get the extension of a file.
   */
  public static String getExtension(File f) {

    String ext = null;
    String s = f.getName();
    int i = s.lastIndexOf('.');

    if ((i > 0) && (i < s.length() - 1)) {
      ext = s.substring(i + 1)
        .toLowerCase();
    }
    return ext;
  }
}

public class VideoFilter implements FileFilter {

  static FileFilter videoFilter;

  public static FileFilter getInstance() {
    if (videoFilter == null) {
      videoFilter = new VideoFilter();
    }
    return videoFilter;
  }

  @Override
  public boolean accept(File f) {
    if (f.isDirectory()) {
      return true;
    }
    String extension = Utils.getExtension(f);
    if (extension != null) {
      if (Utils.selection.contains(extension)) {
        return true;
      } else {
        return false;
      }
    }
    return false;
  }

}
